#!/bin/bash
yum -y install wget make bzip2 gcc-c++
# yum -y groupinstall "Development Tools"
# yum -y install glibc-static libstdc++-static
gccv=10.1.0
cd ~ && rm -rf gcc-*.tar.*
# create swapfile to enlarge memory
mkdir swap
cd swap
dd if=/dev/zero of=swapfile count=4096 bs=1024k
chmod 600 swapfile
mkswap swapfile
swapon swapfile

#download gcc
wget http://ftp.gnu.org/gnu/gcc/gcc-$gccv/gcc-$gccv.tar.xz
tar xvJf gcc-$gccv.tar.xz
cd gcc-$gccv
./contrib/download_prerequisites
yum -y install libgcc.i686 glibc-devel.i686
./configure --enable-checking=release --enable-languages=c,c++ --disable-multilib
make -j2
make install

# libfile=$(find $HOME/gcc-10.1.0/prev* -name "libstdc++.so.6.*"|grep -v '/32/')
# libfile=$(find $HOME/gcc-$gccv/prev* -name "libstdc++.so.6.*"|grep -v '/32/')
libfile=$(find /usr/local -name "libstdc++.so.6.*"|grep -v "\-gdb")
cp $libfile /usr/lib64
cd /usr/lib64 && rm -f libstdc++.so.6
ln -s ${libfile##*\/} libstdc++.so.6